package flyweight.pattern.demo;

import java.util.Random;

/**
 * @author 逸足天涯
 * @create 2019-10-14 20:53
 */
public class FlyweightPatternModifiedEx {
    public static void main(String[] args) throws Exception{
        RobotFactory myFactory = new RobotFactory();
        System.out.println("\n***Flyweight Pattern Example Modified***");
        /*Here we are trying to get 3 king type robots*/
        Robot shape;
        for (int i = 0; i < 3; i++) {
            shape = (Robot) myFactory.getRobotFromFactory("King");
            shape.setColorOfRobot();
            shape.print();
        }
        for (int i = 0; i < 3; i++) {
            shape = (Robot) myFactory.getRobotFromFactory("Queen");
            shape.setColorOfRobot();
            shape.print();
        }
        int numOfDistinctRobots = myFactory.totalObjectsCreated();
        System.out.println("\nDistinct Robot objects created till now = " + numOfDistinctRobots);
        System.out.println("\n Finally no of Distinct Robot objects created : " + numOfDistinctRobots);
    }
    static String getRamdomRandomColor(){
        Random r = new Random();
        /*You can supply any number of your choice in nextInt argument.
        * we are simply checking the random number generated is an even mumber
        * or an odd number.And base on that we are choosing the color.For simplicity,
        * we'll use only two colors-red and green*/
        int random = r.nextInt(20);
        if (random%2 == 0){
            return "red";
        }else {
            return "green";
        }
    }

}